package com.yuxi.Controller.Impl;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.google.gson.Gson;

import com.yuxi.Controller.PrisonController;
import com.yuxi.Dao.InformationPortPowerDao;
import com.yuxi.Dao.InformationSourceDao;
import com.yuxi.Dao.ModifyInformationRecordDao;
import com.yuxi.Dao.PowerRoleDao;
import com.yuxi.Entity.CommentRecord;
import com.yuxi.Entity.CommentRecordBrowse;
import com.yuxi.Entity.ConferenceRecord;
import com.yuxi.Entity.EvaluationRecord;
import com.yuxi.Entity.EvaluationRecordBrowse;
import com.yuxi.Entity.Information;
import com.yuxi.Entity.InformationClassification;
import com.yuxi.Entity.InformationFlow;
import com.yuxi.Entity.InformationOperationRecord;
import com.yuxi.Entity.InformationPort;
import com.yuxi.Entity.InformationPortPower;
import com.yuxi.Entity.InformationQuality;
import com.yuxi.Entity.InformationSort;
import com.yuxi.Entity.InformationSource;
import com.yuxi.Entity.ModifyInformationRecord;
import com.yuxi.Entity.Position;
import com.yuxi.Entity.PowerModule;
import com.yuxi.Entity.PowerRole;
import com.yuxi.Entity.PrisonRole;
import com.yuxi.Entity.PrisonStructure;
import com.yuxi.Entity.Role;
import com.yuxi.Entity.TaskCompletion;
import com.yuxi.Entity.TaskDispatch;
import com.yuxi.Entity.UserInfo;
import com.yuxi.Entity.UserPosition;
import com.yuxi.Entity.UserView;
import com.yuxi.Request.InformationQuery;
import com.yuxi.Request.Page;
import com.yuxi.Request.PageReturn;
import com.yuxi.Request.UserQuery;
import com.yuxi.Response.Obj;
import com.yuxi.Response.PageQuerySave;
import com.yuxi.Service.InformationFlowService;
import com.yuxi.Service.PrisonService;
import com.yuxi.Service.UserService;
import com.yuxi.Service.Impl.InformationFlowServiceImpl;
import com.yuxi.Util.MyMd5Util;
import com.yuxi.Util.StructureLevel;
import com.yuxi.view.UserPowerView;
@Controller
public class PrisonControllerImpl implements PrisonController {
	@Autowired
	private PrisonService prisonService;
	@Autowired
	private UserService userService;
	@Autowired
	private InformationFlowService informationFlowService;
	@Autowired
	private ModifyInformationRecordDao modifyInformationRecordDao;
	private Gson gson= new Gson();
	@Override
	public String addPrisonStructure(PrisonStructure pStructure) {
		try {
			if(pStructure.getName()==null){
				Obj obj=new Obj(false, "添加监狱结构失败", null,  System.currentTimeMillis(), "10001", "监狱结构添加操作");
				return gson.toJson(obj);
			}
			PrisonStructure p= prisonService.addStructure(pStructure);
			Obj obj=new Obj(true, "添加监狱结构成功", p, System.currentTimeMillis(), null, "监狱结构添加操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			// TODO: handle exception
			Obj obj=new Obj(false, "添加监狱结构失败", null,  System.currentTimeMillis(), "10002", "监狱结构添加操作");
			return gson.toJson(obj);
		}
		
		
	}
	@Override
	public String getPrisonStructureById(Integer id) {
		try {
			
			PrisonStructure p= prisonService.getStructure(id);
			Obj obj=new Obj(true, "获取监狱结构成功", p, System.currentTimeMillis(), null, "监狱结构获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			// TODO: handle exception
			Obj obj=new Obj(false, "获取监狱结构失败", null,  System.currentTimeMillis(), "10002", "监狱结构获取操作");
			return gson.toJson(obj);
		}
		
		
	}
	@Override
	public String modifyPrisonStructure(PrisonStructure pStructure) {
		try {
			if(pStructure.getName()==null){
				Obj obj=new Obj(false, "修改监狱结构失败", null,  System.currentTimeMillis(), "10001", "监狱结构修改操作");
				return  gson.toJson(obj);
			}
			prisonService.modifyStructure(pStructure);
			Obj obj=new Obj(true, "修改监狱结构成功", pStructure,  System.currentTimeMillis(), null, "监狱结构修改操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改监狱结构失败", null,  System.currentTimeMillis(), "10002", "监狱结构修改操作");
			return  gson.toJson(obj);
		}
	}
		
	@Override
	public String getAllStructure() {
		try {
			List<PrisonStructure> pStructures = prisonService.getAllStructure();
			Obj obj=new Obj(true, "获取所有监狱结构成功", pStructures,  System.currentTimeMillis(), null, "监狱结构获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取所有监狱结构失败", null,  System.currentTimeMillis(), "10001", "监狱结构获取操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String getAllStructureBySuperId(Integer superId) {
		try {
			List<PrisonStructure> pStructures = prisonService.getAllStructureBySuperId(superId);
			if(pStructures.size()<=0){
				Obj obj=new Obj(false, "获取监狱结构失败",null ,  System.currentTimeMillis(), "10001", "监狱结构修改操作");
				return  gson.toJson(obj);
			}
			Obj obj=new Obj(true, "获取监狱结构成功", pStructures,  System.currentTimeMillis(), null, "监狱结构获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取监狱结构失败",null ,  System.currentTimeMillis(), "10002", "监狱结构修改操作");
			return  gson.toJson(obj);
		}
		
	}

	@Override
	public String deleteStructureById(PrisonStructure pStructure) {
		try {
			prisonService.deleteStructure(pStructure);
			Obj obj=new Obj(true, "删除监狱结构失败",pStructure ,  System.currentTimeMillis(), null, "删除结构修改操作");
			return  gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "删除监狱结构失败",null ,  System.currentTimeMillis(), "10001", "删除结构操作");
			return  gson.toJson(obj);
		}
		
		
	}

	

	@Override
	public String getAllInfomationSort() {
		try {
			List<InformationSort> informationSorts= prisonService.getAllInformationSort();
			Obj obj=new Obj(true, "获取所有信息分类成功",informationSorts ,  System.currentTimeMillis(), null, "信息分类获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取所有信息分类失败",null ,  System.currentTimeMillis(), "10001", "信息分类获取操作");
			return gson.toJson(obj);
		}
		
		
	}

	@Override
	public String getAllInfomationSource() {
		try {
			List<InformationSource> iSources= prisonService.getAllInformationSource();
			Obj obj=new Obj(true, "获取信息渠道成功",iSources ,  System.currentTimeMillis(), null, "信息渠道获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取信息渠道失败",null ,  System.currentTimeMillis(), "1001", "信息渠道获取操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String getAllInformationClassification() {
		try {
			List<InformationClassification> classifications= prisonService.getAllInformationClassification();
			Obj obj=new Obj(true, "获取信息分级成功",classifications ,  System.currentTimeMillis(), null, "信息分级获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取信息分级失败",null ,  System.currentTimeMillis(), "1001", "信息分级获取操作");
			return gson.toJson(obj);
		}
		
	
	}

	@Override
	public String getAllTasCompletion() {
		try {
			// TODO Auto-generated method stub
			List<TaskCompletion> tCompletions= prisonService.getAllTaskCompletion();
			Obj obj=new Obj(true, "获取信息完成等级成功",tCompletions ,  System.currentTimeMillis(), null, "任务完成等级获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取信息完成等级失败",null ,  System.currentTimeMillis(), "1001", "任务完成等级获取操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String getAllInformationQuality() {
		try {
			List<InformationQuality> iQualities= prisonService.getAllInformationQuality();
			Obj obj=new Obj(true, "获取信息等级成功",iQualities ,  System.currentTimeMillis(), null, "信息等级获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取信息等级失败",null ,  System.currentTimeMillis(), "10001", "信息等级获取操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String addQuality(InformationQuality iQuality) {
		try {
			if (iQuality.getName()==null) {
				Obj obj=new Obj(false, "添加信息质量等级失败", null, System.currentTimeMillis(), "10001", "添加操作");
				return gson.toJson(obj);
			}
			// TODO Auto-generated method stub
			InformationQuality iq= prisonService.addQuality(iQuality);
			Obj obj=new Obj(true, "添加信息质量等级成功", iq, System.currentTimeMillis(), null, "添加操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "添加信息质量等级失败", null, System.currentTimeMillis(), "10002", "添加操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String addCompletion(TaskCompletion tCompletion) {
		try {
			if (tCompletion.getName()==null||tCompletion.getScore()<0) {
				Obj obj=new Obj(false, "添加任务完成等级失败",null, System.currentTimeMillis(), "10001", "添加操作");
				return gson.toJson(obj);
			}
			// TODO Auto-generated method stub
			TaskCompletion t= prisonService.addCompletion(tCompletion);
			Obj obj=new Obj(true, "添加任务完成等级成功", t, System.currentTimeMillis(), null, "添加操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "添加任务完成等级失败",null, System.currentTimeMillis(), "10002", "添加操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String modifyQuality(InformationQuality iQuality) {
		try {
			prisonService.modifyQuality(iQuality);
			Obj obj=new Obj(true, "修改信息质量等级成功", iQuality,  System.currentTimeMillis(), null, "修改操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改信息质量等级失败", null,  System.currentTimeMillis(), "10001", "修改操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String modifyCompletion(TaskCompletion tCompletion) {
		try {
			// TODO Auto-generated method stub
			prisonService.modifyCompletion(tCompletion);
			Obj obj=new Obj(true, "修改任务等级成功", tCompletion,  System.currentTimeMillis(), null, "修改操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改任务等级失败", null,  System.currentTimeMillis(), "10001", "修改操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String delCompletion(TaskCompletion tCompletion) {
		try {
			prisonService.deleteCompletion(tCompletion);
			Obj obj=new Obj(true, "添加信息质量等级成功",  tCompletion,System.currentTimeMillis(), null, "删除操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "添加信息质量等级失败", null, System.currentTimeMillis(), "10001", "删除操作");
			return gson.toJson(obj);
		}
		
		
	}

	@Override
	public String delQuality(InformationQuality iQuality) {
		try {
			prisonService.deleteQuality(iQuality);
			Obj obj=new Obj(true, "删除信息质量等级成功", iQuality, System.currentTimeMillis(), null, "删除操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "删除信息质量等级失败", null, System.currentTimeMillis(), "10001", "删除操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String addInfoSort(InformationSort iSort) {
		try {
			if(iSort.getName()==null){
				Obj obj=new Obj(false, "添加信息分类失败", null,  System.currentTimeMillis(), "10001", "信息分类添加操作");
				return gson.toJson(obj);
			}
			iSort= prisonService.addInfoSort(iSort);
			Obj obj=new Obj(true, "添加信息分类成功", iSort, System.currentTimeMillis(), null, "信息分类添加操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "添加信息分类失败", null,  System.currentTimeMillis(), "10002", "信息分类添加操作");
			return gson.toJson(obj);
		}
		
		
	}

	@Override
	public String addInfoSource(InformationSource iSource) {
		try {
			if(iSource.getName()==null){
				Obj obj=new Obj(false, "添加信息渠道失败", null,  System.currentTimeMillis(), "10001", "信息渠道添加操作");
				return gson.toJson(obj);
			}
			boolean flag= prisonService.addInfoSource(iSource);
			if (flag) {
				Obj obj=new Obj(true, "添加信息渠道成功", iSource, System.currentTimeMillis(), null, "信息渠道添加操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "添加信息渠道失败", null,  System.currentTimeMillis(), "10003", "信息渠道添加操作");
				return gson.toJson(obj);
			}
		
		} catch (Exception e) {
			Obj obj=new Obj(false, "添加信息渠道失败", null,  System.currentTimeMillis(), "10002", "信息渠道添加操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String addInfoClassification(InformationClassification iClassification) {
		try {
			if(iClassification.getName()==null){
				Obj obj=new Obj(false, "添加信息分级失败", null,  System.currentTimeMillis(), "10001", "信息分级添加操作");
				return gson.toJson(obj);
			}
			iClassification= prisonService.addInfoClassification(iClassification);
			Obj obj=new Obj(true, "添加信息分级成功", iClassification, System.currentTimeMillis(), null, "信息分级添加操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "添加信息分级失败", null,  System.currentTimeMillis(), "10002", "信息分级添加操作");
			return gson.toJson(obj);
		}
		
		
	}

	@Override
	public String modifyInfoSort(InformationSort iSort) {
		try {
			prisonService.modifyInfoSort(iSort);
			Obj obj=new Obj(true, "修改信息分类成功", iSort, System.currentTimeMillis(), null, "信息分类修改操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改信息分类成功", null, System.currentTimeMillis(), "10001", "信息分类修改操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String modifyInfoSource(Integer id,Integer level,Integer superId,  String name,String remark,Integer lastSuperId) {
		try {
			if (prisonService.modifyInfoSource(id,level,superId,name,remark,lastSuperId)) {
				  Obj obj=new Obj(true, "修改信息渠道成功", null,  System.currentTimeMillis(), null, "信息渠道修改操作");
					return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "修改信息渠道失败", null,  System.currentTimeMillis(), "10002", "信息渠道修改操作");
				return gson.toJson(obj);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			Obj obj=new Obj(false, "修改信息渠道失败", null,  System.currentTimeMillis(), "10001", "信息渠道修改操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String modifyInfoClassification(InformationClassification iClassification) {
		try {
			prisonService.modifyInfoClassification(iClassification);
			Obj obj=new Obj(true, "修改信息分级成功", iClassification, System.currentTimeMillis(), null, "信息分级修改操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改信息分级失败", null,  System.currentTimeMillis(), "10001", "信息分级修改操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String delInfoSort(InformationSort iSort) {
		try {
			prisonService.delInfoSort(iSort);
			Obj obj=new Obj(true, "删除信息分类成功", iSort, System.currentTimeMillis(), null, "信息分类删除操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "删除信息分类失败", null,  System.currentTimeMillis(), "10001", "信息分类删除操作");
			return gson.toJson(obj);
		}
		
		
	}

	@Override
	public String delInfoSource(InformationSource iSource) {
		try {
			prisonService.delInfoSource(iSource);
			Obj obj=new Obj(true, "删除信息渠道成功", iSource, System.currentTimeMillis(), null, "信息渠道删除操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "删除信息渠道失败", null,  System.currentTimeMillis(), "10001", "信息渠道删除操作");
			return gson.toJson(obj);
		}
		
		
		
	}

	@Override
	public String delInfoClassification(InformationClassification iClassification) {
		try {
			prisonService.delInfoClassification(iClassification);
			Obj obj=new Obj(true, "删除信息分级成功", iClassification, System.currentTimeMillis(), null, "信息分级删除操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "删除信息分级失败", iClassification,  System.currentTimeMillis(), "10001", "信息分级删除操作");
			return gson.toJson(obj);
		}
		
		
	}

	@Override
	public String modifyPowerModule(PowerModule pModule) {
		try {
			prisonService.modifyPowerModule(pModule);			
			Obj obj=new Obj(true, "修改模块权限成功", null, System.currentTimeMillis(), null, "修改模块权限操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改模块权限失败",null, System.currentTimeMillis(), "10001", "修改说模块权限操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String getPowerModuleByName(String name) {
		try {
			PowerModule pModule = prisonService.getPowerModuleByName(name);
			Obj obj=new Obj(true, "通过模块名获取模块权限成功", pModule, System.currentTimeMillis(), null, "获取模块权限操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "通过模块名获取模块权限失败",null, System.currentTimeMillis(), "10001", "获取模块权限操作");
			return gson.toJson(obj);
		}

	}

	@Override
	public String getAllPrisonRole() {
		try {
		List<PrisonRole> pRoles=	prisonService.getAllPrisonRole();
			Obj obj=new Obj(true, "获取所有监狱角色成功",pRoles ,  System.currentTimeMillis(), null, "监狱角色获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取所有监狱角色失败",null ,  System.currentTimeMillis(), "10001", "监狱角色获取操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String modifyePrisonRole(String pRole,String powerRoleStr,String portStr) {
		try {
			Role  role=new Gson().fromJson(pRole, Role.class);
			PowerRole powerRole=new Gson().fromJson(powerRoleStr, PowerRole.class);
			if (role.getRoleName()==null||role.getRoleName().equals("")||role.getRoleName().equals("null")) {
				Obj obj=new Obj(false, "修改监狱角色失败", null,  System.currentTimeMillis(), "10003", "修改操作");
				return gson.toJson(obj);
			}
			boolean flag = prisonService.modifyPrisonRole(role,powerRole,portStr);
			if(flag){
				Obj obj=new Obj(true, "修改监狱角色成功",null ,  System.currentTimeMillis(), null, "修改操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "修改监狱角色失败", null,  System.currentTimeMillis(), "10002", "修改操作");
				return gson.toJson(obj);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			Obj obj=new Obj(false, "修改监狱角色失败", null,  System.currentTimeMillis(), "10001", "修改操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String delPrisonRole(Role role) {
		try {
			boolean flag = prisonService.delPrisonRole(role);
			if (flag) {
				Obj obj=new Obj(true, "删除监狱角色成功", null,  System.currentTimeMillis(), null, "删除操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "删除监狱角色失败", null,  System.currentTimeMillis(), "10002", "删除操作");
				return gson.toJson(obj);
			}
		
		} catch (Exception e) {
			Obj obj=new Obj(false, "删除监狱角色失败", null,  System.currentTimeMillis(), "10001", "删除操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String addPrisonRole(String pRoleStr,String powerRoleStr,String portStr) {
		Role  role=new Gson().fromJson(pRoleStr, Role.class);
		PowerRole powerRole=new Gson().fromJson(powerRoleStr, PowerRole.class);
		try {
			if(role.getRoleName()==null){
				Obj obj=new Obj(false, "添加监狱角色失败", null,  System.currentTimeMillis(), "10001", "添加操作");
				return gson.toJson(obj);
			}
			role = prisonService.addPrisonRole(role,powerRole,portStr);
			Obj obj=new Obj(true, "添加监狱角色成功", null,  System.currentTimeMillis(), null, "添加操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			e.printStackTrace();
			Obj obj=new Obj(false, "添加监狱角色失败", null,  System.currentTimeMillis(), "10002", "添加操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String getRoleByStructureId(Integer structureId) {
		try {
//			PrisonStructure pStructure=new PrisonStructure();
//			pStructure.setId(structureId);
//			if(structureId==null){
//				
//			}else{
//				
//			}
			List<Position> pRoles =prisonService.getAllPsoition();
			Obj obj=new Obj(true, "通过部门id获取监狱职务成功",pRoles ,  System.currentTimeMillis(), null, "监狱职务获取操作");
			return gson.toJson(obj);
			} catch (Exception e) {	
				e.printStackTrace();
				Obj obj=new Obj(false, "通过部门id获取监狱职务失败",null ,  System.currentTimeMillis(), "10001", "监狱职务获取操作");
				return gson.toJson(obj);
			}
	}

	@Override
	public String getAllPowerModule() {
		try {
			List<PowerModule> pModules =prisonService.getAllModule();
			Obj obj=new Obj(true, "获取所有权限模块成功",pModules ,  System.currentTimeMillis(), null, "模块权限获取操作");
			return gson.toJson(obj);
			} catch (Exception e) {
			Obj obj=new Obj(false, "获取所有权限模块失败",null ,  System.currentTimeMillis(), "10001", "模块权限获取操作");
			return gson.toJson(obj);
			}
	}

	@Override
	public String getPowerByRoleId(Integer roleId) {
		// TODO Auto-generated method stub
		try {
			List<PowerRole> pRoles =prisonService.getPowerByRoleId(roleId);
			Obj obj=new Obj(true, "根据角色id获取权限模块成功",pRoles ,  System.currentTimeMillis(), null, "模块权限获取操作");
			return gson.toJson(obj);
			} catch (Exception e) {
				Obj obj=new Obj(false, "根据角色id获取所有权限模块失败",null ,  System.currentTimeMillis(), "10001", "模块权限获取操作");
				return gson.toJson(obj);
			}
	}


	@Override
	public String getPrisonRoleById(Integer id) {
		try {
			Role pRole =new Role();
			pRole=prisonService.getPrisonRoleById(id);
			Obj obj=new Obj(true, "根据id获取角色成功",pRole ,  System.currentTimeMillis(), null, "角色获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "根据id获取角色失败",null ,  System.currentTimeMillis(), "10001", "角色获取操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String getStructucreLevel() {
		try {
			List<PrisonStructure> pStructures=prisonService.getAllStructure();
			List<StructureLevel> structucreLevels=new ArrayList<StructureLevel>();
			int superId=0;
			for (PrisonStructure p:pStructures) {
				if(p.getSuperId()==0){
					StructureLevel sLevel=new StructureLevel(p.getId(), p.getName(), p.getSuperId(), 1);
					structucreLevels.add(sLevel);
					superId=p.getId();
				}
			}
			structucreLevels=getLevel(superId, 1, structucreLevels,pStructures);
			Obj obj=new Obj(true, "获取监狱部门等级成功",structucreLevels ,  System.currentTimeMillis(), null, "获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(true, "获取监狱部门等级失败",null ,  System.currentTimeMillis(), "10001", "获取操作");
			return gson.toJson(obj);	
		}	
	}
	public  List<StructureLevel> getLevel(int superId,int level,List<StructureLevel> structucreLevels,List<PrisonStructure> pStructures){
		for (int i=0;i<pStructures.size();i++) {
			PrisonStructure p=pStructures.get(i);
			if((p.getSuperId()==superId)){
				StructureLevel sLevel=new StructureLevel(p.getId(), p.getName(), p.getSuperId(), level+1);
				structucreLevels.add(sLevel);
				getLevel(p.getId(), sLevel.getSort(), structucreLevels,pStructures);
			}
			
		}
		return structucreLevels;
	}

	@Override
	public String getSafetyPortList(HttpSession session) {
		try {
			UserInfo u=userService.getCurLoginUser(session);
			List<PrisonStructure> prisonStructures=userService.userGetsafetyPortList(u);
			Obj obj=new Obj(true, "获取分口成功", prisonStructures,  System.currentTimeMillis(), null, "获取分口操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取分口失败", null,  System.currentTimeMillis(), "10001", "获取分口操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getUserListByAccountOrName(String userAccountOrName) {
		// TODO Auto-generated method stub
		try {
			System.out.println(userAccountOrName);
			List<UserInfo> uList =	prisonService.getUserListByAccountOrName(userAccountOrName);
			Obj obj=new Obj(true, "获取用户成功", uList,  System.currentTimeMillis(), null, "获取用户操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取用户失败", null,  System.currentTimeMillis(), "10001", "获取用户操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String userMoidfyPassword(String oldPassword, String newPassword,HttpSession session) {
		try {
			if(newPassword!="" &&newPassword.length()>=6&& newPassword.length()<=16){
				UserInfo uInfo = userService.getCurLoginUser(session);
				oldPassword= MyMd5Util.stringToMd5(oldPassword);
				newPassword=MyMd5Util.stringToMd5(newPassword);
				if(uInfo.getUserPassword().equals(oldPassword)){
					uInfo.setUserPassword(newPassword);
					if(prisonService.modifyUserPassword(uInfo)){
						Obj obj=new Obj(true, "修改密码成功。", null,  System.currentTimeMillis(), null, "用户修改密码操作");
						return gson.toJson(obj);
					}
				}else {
					Obj obj=new Obj(false, "旧密码错误!", null,  System.currentTimeMillis(), "10001", "用户修改密码操作");
					return gson.toJson(obj);
				}
			}
			Obj obj=new Obj(false, "新密码不能为空并且长度为6~16.", null,  System.currentTimeMillis(), "10002", "用户修改密码操作");
			return gson.toJson(obj);
		
		
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改密码失败", null,  System.currentTimeMillis(), "10003", "用户修改密码操作");
			return gson.toJson(obj);
		}
		
		
				
		
	}

	@Override
	public String quitLogin(HttpSession session) {
		session.removeAttribute("user");
		Obj obj=new Obj(true, "注销成功！", null,  System.currentTimeMillis(), null, "注销登录操作");
		return gson.toJson(obj);
	}

	@Override
	public String getRecordByInfoId(Integer infoId) {
		try {
			ConferenceRecord conferenceRecord = prisonService.getRecordByInfoId(infoId);
			Obj obj=new Obj(true, "获取会议记录 成功", conferenceRecord,  System.currentTimeMillis(), null, "获取会议记录操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取会议记录失败", null,  System.currentTimeMillis(), "10001", "获取会议记录操作");
			return gson.toJson(obj);

		}
	}

	@Override
	public String addSuperStructure(PrisonStructure pStructure) {
		try {
			
			if(pStructure.getName()==null){
				Obj obj=new Obj(false, "添加监狱结构失败", null,  System.currentTimeMillis(), "10001", "监狱结构添加操作");
				return gson.toJson(obj);
			}
			PrisonStructure p= prisonService.addSuperStructure(pStructure);
			Obj obj=new Obj(true, "添加监狱结构成功", p, System.currentTimeMillis(), null, "监狱结构添加操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			
			Obj obj=new Obj(false, "添加监狱结构失败", null,  System.currentTimeMillis(), "10002", "监狱结构添加操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getAllSuperStructure() {
		try {
			List<PrisonStructure> pStructures = prisonService.getAllSuperStructure();
			Obj obj=new Obj(true, "获取所有监狱结构成功", pStructures,  System.currentTimeMillis(), null, "监狱结构获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取所有监狱结构失败", null,  System.currentTimeMillis(), "10001", "监狱结构获取操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String getAllPrisonArea() {
		try {
			List<PrisonStructure> pStructures = prisonService.getAllPrisonArea();
			Obj obj=new Obj(true, "获取所有监区成功", pStructures,  System.currentTimeMillis(), null, "监狱结构获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取所有监区失败", null,  System.currentTimeMillis(), "10001", "监狱结构获取操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getSuperAndSubordinate(HttpSession session) {
		try {
			UserInfo userInfo = userService.getCurLoginUser(session);
			List<PrisonStructure> pStructures = new ArrayList<PrisonStructure>();
			pStructures=prisonService.getAllStructure();	
			Obj obj=new Obj(true, "获取上级及所有下级部门成功", pStructures,  System.currentTimeMillis(), null, "监狱结构获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取上级及所有下级部门失败", null,  System.currentTimeMillis(), "10001", "监狱结构获取操作");
			return gson.toJson(obj);
		}
		
	}

	@Override
	public String getOperationByInfoId(Integer infoId) {
		try {
			List<InformationOperationRecord> operationRecords=prisonService.getOperationByInfoId(infoId);
			if(operationRecords.size()<=0){
				Obj obj=new Obj(false, "获取信息操作记录失败", null,  System.currentTimeMillis(), "10001", "信息操作记录获取操作");
				return gson.toJson(obj);
			}
			Obj obj=new Obj(true, "获取信息操作记录成功", operationRecords,  System.currentTimeMillis(), null, "信息操作记录获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取信息操作记录失败", null,  System.currentTimeMillis(), "10002", "信息操作记录获取操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getTaskDispatchByInfoId(int infoId) {
		try {
			List<TaskDispatch> taskDispatchs=prisonService.getTaskDispatchByInfoId(infoId);
			if(taskDispatchs==null){
				Obj obj=new Obj(false, "获取任务派遣记录失败", null,  System.currentTimeMillis(), "10001", "任务派遣记录获取操作");
				return gson.toJson(obj);
			}
			Obj obj=new Obj(true, "获取任务派遣记录成功", taskDispatchs,  System.currentTimeMillis(), null, "任务派遣记录获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取任务派遣记录失败", null,  System.currentTimeMillis(), "10002", "任务派遣记录获取操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getCommentRecordByInfoId(int infoId) {
		try {
			CommentRecord commentRecord=prisonService.getCommentRecordByInfoId(infoId);
			if(commentRecord==null){
				Obj obj=new Obj(false, "获取信息点评记录失败", null,  System.currentTimeMillis(), "10001", "信息点评获取操作");
				return gson.toJson(obj);
			}
			Obj obj=new Obj(true, "获取信息点评记录成功", commentRecord,  System.currentTimeMillis(), null, "信息点评获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获信息点评记录失败", null,  System.currentTimeMillis(), "10002", "信息点评获取操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getEvaluationRecordByInfoId(int infoId,HttpSession session) {
		try {
			UserInfo userInfo= userService.getCurLoginUser(session);
			EvaluationRecord evaluationRecord=prisonService.getEvaluationRecordByInfoId(infoId,userInfo.getUserId());
			if(evaluationRecord==null){
				Obj obj=new Obj(false, "获取信息点评记录失败", null,  System.currentTimeMillis(), "10001", "信息评价获取操作");
				return gson.toJson(obj);
			}
			Obj obj=new Obj(true, "获取信息评价记录成功", evaluationRecord,  System.currentTimeMillis(), null, "信息评价获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取信息评价记录失败", null,  System.currentTimeMillis(), "10002", "信息评价获取操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String getAllEvaluationRecord(int infoId,HttpSession session) {
		try {
			UserInfo userInfo= userService.getCurLoginUser(session);
			List<EvaluationRecord> evaluationRecords=prisonService.getAllEvaluationRecord(infoId,userInfo.getUserId());
			if(evaluationRecords==null||evaluationRecords.isEmpty()||evaluationRecords.size()==0){
				Obj obj=new Obj(false, "获取信息点评记录失败", null,  System.currentTimeMillis(), "10001", "信息评价获取操作");
				return gson.toJson(obj);
			}
			Obj obj=new Obj(true, "获取信息评价记录成功", evaluationRecords,  System.currentTimeMillis(), null, "信息评价获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取信息评价记录失败", null,  System.currentTimeMillis(), "10002", "信息评价获取操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String getInformationFlowByInfoId(int infoId) {
		try {
			List<InformationFlow> iFlows = informationFlowService.getInformationFlowByInfoId(infoId);
			if(iFlows==null||iFlows.size()==0){
				Obj obj=new Obj(false, "获取信息流程记录失败", null,  System.currentTimeMillis(), "10001", "信息流程获取操作");
				return gson.toJson(obj);
			}
			Obj obj=new Obj(true, "获取信息流程记录成功", iFlows,  System.currentTimeMillis(), null, "信息流程获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取信息流程记录成功", null,  System.currentTimeMillis(), "10002", "信息流程获取操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String addCommentRecorBrowse(int infoId, HttpSession session, HttpServletRequest request) {
		try {
			Boolean flag= prisonService.addCommentRecordBrowse(infoId, userService.getCurLoginUser(session));
			if(flag){
				Obj obj=new Obj(true, "添加点评浏览记录成功", null,  System.currentTimeMillis(), null, "点评记录添加操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "添加点评浏览记录失败", null,  System.currentTimeMillis(), "10001", "点评记录添加操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "添加点评浏览记录失败", null,  System.currentTimeMillis(), "10002", "点评记录添加操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String addEvaluationRecorBrowse(int infoId, HttpSession session, HttpServletRequest request) {
		try {
			Boolean flag= prisonService.addEvaluationRecordBrowse(infoId, userService.getCurLoginUser(session));
			if(flag){
				Obj obj=new Obj(true, "添加评价浏览记录成功", null,  System.currentTimeMillis(), null, "评价记录添加操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "添加评价浏览记录失败", null,  System.currentTimeMillis(), "10001", "评价记录添加操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			e.printStackTrace();
			Obj obj=new Obj(false, "添加评价浏览记录失败", null,  System.currentTimeMillis(), "10002", "评价记录添加操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String modifyCommentRecorBrowse(int infoId, int id,HttpSession session, HttpServletRequest request) {
		try {
			Boolean flag= prisonService.modifyCommentRecordBrowse(infoId, id,userService.getCurLoginUser(session));
			if(flag){
				Obj obj=new Obj(true, "修改点评浏览记录成功", null,  System.currentTimeMillis(), null, "点评记录修改操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "修改点评浏览记录失败", null,  System.currentTimeMillis(), "10001", "点评记录修改操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			e.printStackTrace();
			Obj obj=new Obj(false, "修改点评浏览记录失败", null,  System.currentTimeMillis(), "10002", "点评记录修改操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String modifyEvaluationRecorBrowse(int infoId,HttpSession session, HttpServletRequest request) {
		try {
			Boolean flag= prisonService.modifyEvaluationRecordBrowse(infoId,userService.getCurLoginUser(session));
			if(flag){
				Obj obj=new Obj(true, "修改评价浏览记录成功", null,  System.currentTimeMillis(), null, "评价记录修改操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "修改评价浏览记录失败", null,  System.currentTimeMillis(), "10001", "评价记录修改操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改评价浏览记录失败", null,  System.currentTimeMillis(), "10002", "评价记录修改操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String getCommentBrowseByInfoId(int infoId) {
		try {
			List<CommentRecordBrowse> cBrowses = prisonService.getCommentRecordBrowseByInfoId(infoId);
			if(cBrowses!=null && cBrowses.size()!=0){
				Obj obj=new Obj(true, "获取点评浏览记录成功", cBrowses,  System.currentTimeMillis(), null, "点评记录获取操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "获取点评浏览记录失败", null,  System.currentTimeMillis(), "10001", "点评记录获取操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取点评浏览记录失败", null,  System.currentTimeMillis(), "10002", "点评记录获取操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String getEvaluationBrowseByInfoId(int infoId,int eRecordId) {
		try {
			List<EvaluationRecordBrowse> cBrowses = prisonService.getEvaluationRecordBrowseByInfoId(infoId,eRecordId);
			if(cBrowses!=null && cBrowses.size()!=0){
				Obj obj=new Obj(true, "获取评价浏览记录成功", cBrowses,  System.currentTimeMillis(), null, "评价记录获取操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "获取评价浏览记录失败", null,  System.currentTimeMillis(), "10001", "评价记录获取操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			e.printStackTrace();
			Obj obj=new Obj(false, "获取评价浏览记录失败", null,  System.currentTimeMillis(), "10002", "评价记录获取操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String addInformationPort(InformationPort informationPort) {
		try {
			if (informationPort.getPortName()==null) {
				Obj obj=new Obj(false, "添加信息分口失败", null,  System.currentTimeMillis(), "10003", "信息分口添加操作");
				return gson.toJson(obj);
			}
			informationPort = prisonService.addInformationPort(informationPort);
			if (informationPort==null) {
				Obj obj=new Obj(false, "添加信息分口失败", null,  System.currentTimeMillis(), "10001", "信息分口添加操作");
				return gson.toJson(obj);
			}else {
				Obj obj=new Obj(true, "添加信息分口成功", null,  System.currentTimeMillis(), null, "信息分口添加操作");
				return gson.toJson(obj);
			}
			
		} catch (Exception e) {
			Obj obj=new Obj(false, "添加信息分口失败", null,  System.currentTimeMillis(), "10002", "信息分口添加操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getAllInformationPort() {
		try {
			List<InformationPort> informationPorts = prisonService.getAllInformationPort();
			if (informationPorts== null || informationPorts.size()<=0) {
				Obj obj=new Obj(false, "获取所有信息分口失败", null,  System.currentTimeMillis(), "10001", "信息分口获取操作");
				return gson.toJson(obj);
			}else {
				Obj obj=new Obj(true, "获取所有信息分口成功", informationPorts,  System.currentTimeMillis(), null, "信息分口获取操作");
				return gson.toJson(obj);
			}
 		} catch (Exception e) {
 			Obj obj=new Obj(false, "获取所有信息分口失败", null,  System.currentTimeMillis(), "10002", "信息分口获取操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String modifyInformationPort(Integer id,Integer level,Integer superId, String name,String remark,Integer lastSuperId) {
		try {
			boolean flag = prisonService.modifyInformationPort(id,level,superId,name,remark,lastSuperId);
			if (flag) {
				Obj obj=new Obj(true, "修改信息分口成功", null,  System.currentTimeMillis(), null, "信息分口修改操作");
				return gson.toJson(obj);
			}else {
				Obj obj=new Obj(false, "修改信息分口失败", null,  System.currentTimeMillis(), "10001", "信息分口修改操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改信息分口失败", null,  System.currentTimeMillis(), "10002", "信息分口修改操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String deleteInformationPort(InformationPort informationPort) {
		try {
			boolean flag = prisonService.deleteInformationPort(informationPort);
			if (flag) {
				Obj obj=new Obj(false, "删除信息分口成功", null,  System.currentTimeMillis(), null, "信息分口删除操作");
				return gson.toJson(obj);
			}else {
				Obj obj=new Obj(false, "删除信息分口失败", null,  System.currentTimeMillis(), "10001", "信息分口删除操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "删除信息分口失败", null,  System.currentTimeMillis(), "10002", "信息分口删除操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getPortPowerByRoleId(Integer roleId) {
		try {
			
			List<InformationPortPower> portPowers = prisonService.getPortPowerByRoleId(roleId);
			if(portPowers==null){
				Obj obj=new Obj(false, "获取角色分口权限失败", null,  System.currentTimeMillis(), "10001", "角色分口权限获取操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(true, "获取角色分口权限成功", portPowers,  System.currentTimeMillis(), null, "角色分口权限获取操作");
				return gson.toJson(obj);
			}
			
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取角色分口权限失败", null,  System.currentTimeMillis(), "10002", "角色分口权限获取操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String addPosition(Position position) {
		try {
			boolean flag=prisonService.addPosition(position);
			if (flag) {
				Obj obj=new Obj(true, "添加职务成功", null,  System.currentTimeMillis(), null, "添加职务操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "添加职务失败", null,  System.currentTimeMillis(), "10001", "添加职务操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			e.printStackTrace();
			Obj obj=new Obj(false, "添加职务失败", null,  System.currentTimeMillis(), "10002", "添加职务操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String addUserPosition(UserPosition userPosition) {
		try {
			boolean flag=prisonService.addUserPosition(userPosition);
			if (flag) {
				Obj obj=new Obj(true, "用户绑定职务成功", null,  System.currentTimeMillis(), null, "用户绑定职务操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "用户绑定职务成功", null,  System.currentTimeMillis(), "10001", "用户绑定职务操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "用户绑定职务成功", null,  System.currentTimeMillis(), "10002", "用户绑定职务操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String deletePosition(Position position) {
		try {
			boolean flag=prisonService.deletePosition(position);
			if (flag) {
				Obj obj=new Obj(true, "删除职务成功", null,  System.currentTimeMillis(), null, "删除职务操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "删除职务失败", null,  System.currentTimeMillis(), "10001", "删除职务操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "删除职务失败", null,  System.currentTimeMillis(), "10002", "删除职务操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String deleteUserPosition(UserPosition userPosition) {
		try {
			boolean flag=prisonService.deleteUserPosition(userPosition);
			if (flag) {
				Obj obj=new Obj(true, "删除用户职务成功", null,  System.currentTimeMillis(), null, "删除用户职务操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "删除用户职务成功", null,  System.currentTimeMillis(), "10001", "删除用户职务操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "删除用户职务成功", null,  System.currentTimeMillis(), "10002", "删除用户职务操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String modifyPosition(Position position) {
		try {
			boolean flag=prisonService.modifyPosition(position);
			if (flag) {
				Obj obj=new Obj(true, "修改职务成功", null,  System.currentTimeMillis(), null, "修改职务操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "修改职务失败", null,  System.currentTimeMillis(), "10001", "修改职务操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改职务失败", null,  System.currentTimeMillis(), "10002", "修改职务操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String modifyUserPosition(UserPosition userPosition) {
		try {
			boolean flag=prisonService.modifyUserPosition(userPosition);
			if (flag) {
				Obj obj=new Obj(true, "修改用户职务成功", null,  System.currentTimeMillis(), null, "修改用户职务操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "修改用户职务失败", null,  System.currentTimeMillis(), "10001", "修改用户职务操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改用户职务失败", null,  System.currentTimeMillis(), "10002", "修改用户职务操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getAllPsoition() {
		try {
			List<Position> positions =prisonService.getAllPsoition();
			if (positions!=null||positions.size()!=0) {
				Obj obj=new Obj(true, "获取部门职务成功", positions,  System.currentTimeMillis(), null, "获取部门职务操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "获取部门职务失败", null,  System.currentTimeMillis(), "10001", "获取部门职务操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取部门职务失败", null,  System.currentTimeMillis(), "10002", "获取部门职务操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getUserPositionByUserId(Integer userId) {
		try {
			UserPosition userPosition =prisonService.getUserPositionByUserId(userId).get(0);
			if (userPosition!=null) {
				Obj obj=new Obj(true, "获取用户职务成功", userPosition,  System.currentTimeMillis(), null, "获取用户职务操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "获取用户职务失败", null,  System.currentTimeMillis(), "10001", "获取用户职务操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取用户职务失败", null,  System.currentTimeMillis(), "10002", "获取用户职务操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String addRole(Role role) {
		try {
			if(role.getRoleName()==null){
				Obj obj=new Obj(false, "添加角色失败", null,  System.currentTimeMillis(), "10003", "添加角色操作");
				return gson.toJson(obj);
			}
			boolean flag=prisonService.addRole(role);
			if (flag) {
				Obj obj=new Obj(true, "添加角色成功", null,  System.currentTimeMillis(), null, "添加角色操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "添加角色失败", null,  System.currentTimeMillis(), "10001", "添加角色操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "添加角色失败", null,  System.currentTimeMillis(), "10002", "添加角色操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String deleteRole(Role role) {
		try {
			
			boolean flag=prisonService.deleteRole(role);
			if (flag) {
				Obj obj=new Obj(true, "删除角色成功", null,  System.currentTimeMillis(), null, "删除角色操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "删除角色失败", null,  System.currentTimeMillis(), "10001", "删除角色操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "删除角色失败", null,  System.currentTimeMillis(), "10002", "删除角色操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String modifyRole(Role role) {
		try {
			boolean flag=prisonService.modifyRole(role);
			if (flag) {
				Obj obj=new Obj(true, "修改角色成功", null,  System.currentTimeMillis(), null, "修改角色操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "修改角色失败", null,  System.currentTimeMillis(), "10001", "修改角色操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改角色失败", null,  System.currentTimeMillis(), "10002", "修改角色操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getAllRole() {
		try {
			List<Role> roles =prisonService.getAllRole();
			if (roles!=null||roles.size()!=0) {
				Obj obj=new Obj(true, "获取所有角色成功", roles,  System.currentTimeMillis(), null, "获取所有角色操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "获取所有角色失败", null,  System.currentTimeMillis(), "10001", "获取所有角色操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取所有角色失败", null,  System.currentTimeMillis(), "10002", "获取所有角色操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getUserList(UserQuery userQuery, Integer structureId,Page<UserView> p, HttpSession session) {
		
		PageQuerySave<UserQuery> userQueryPage=new PageQuerySave<UserQuery>(userQuery, p.getTotalPage());
		PageQuerySave<UserQuery> userQueryPagecur=(PageQuerySave<UserQuery>)session.getAttribute("userListQuery");
		if(userQueryPagecur!=null&&userQueryPagecur.isEable()){			
			
			userQuery=userQueryPagecur.getQuery();
			p.setCurrentPage(userQueryPagecur.getPageNum());
			userQueryPage.setEable(false);
		}
		
		Page<UserView> rsp=prisonService.getUserList(userQuery, structureId, p);
		userQueryPage.setEable(false);
		session.setAttribute("userListQuery", userQueryPage);
		return gson.toJson(rsp);
	}

	@Override
	public String getDepartmentAndArea() {
		try {
			List<PrisonStructure> pStructures = prisonService.getDepartmentAndPrisonArea();
			Obj obj=new Obj(true, "获取所有科室和监区成功", pStructures,  System.currentTimeMillis(), null, "监狱结构获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取所有科室和监区失败", null,  System.currentTimeMillis(), "10001", "监狱结构获取操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String getPositionById(Integer id) {
		try {
			Position position =	prisonService.getPosition(id);
			Obj obj=new Obj(true, "获取职务信息成功", position,  System.currentTimeMillis(), null, "监狱结构获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(true, "获取职务信息成功", null,  System.currentTimeMillis(), "10001", "监狱结构获取操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String infoSoureCompositor(String idStr,String levelStr) {
		try {
			 if (prisonService.infoSoureCompositor(idStr, levelStr)) {
				Obj obj=new Obj(true, "修改信息渠道排序呢成功",null ,  System.currentTimeMillis(), null, "信息渠道排序操作");
				return gson.toJson(obj);
			}else {
				Obj obj=new Obj(false, "修改信息渠道排序失败",null ,  System.currentTimeMillis(), "10001", "信息渠道排序操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			e.printStackTrace();
			Obj obj=new Obj(false, "修改信息渠道排序失败",null ,  System.currentTimeMillis(), "10002", "信息渠道排序操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String getInfomationSourceBysuperId(Integer superId) {
		try {
			List<InformationSource> sources= prisonService.getInformationSourceBySuperId(superId);
			Obj obj=new Obj(true, "获取所有信息渠道成功",sources ,  System.currentTimeMillis(), null, "信息渠道获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取所有信息渠道失败",null ,  System.currentTimeMillis(), "10001", "信息渠道获取操作");
			return gson.toJson(obj);
		}
		
	}
	@Override
	public String infoPortCompositor(String idStr, String levelStr) {
		try {
			 if (prisonService.infoPortCompositor(idStr, levelStr)) {
				Obj obj=new Obj(true, "修改信息分口排序成功",null ,  System.currentTimeMillis(), null, "信息分口排序操作");
				return gson.toJson(obj);
			}else {
				Obj obj=new Obj(false, "修改信息分口排序失败",null ,  System.currentTimeMillis(), "10001", "信息分口排序操作");
				return gson.toJson(obj);
			}
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改信息分口排序失败",null ,  System.currentTimeMillis(), "10001", "信息分口排序操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String getInfomationPortBysuperId(Integer superId) {
		try {
			List<InformationPort> ports= prisonService.getInformationPortBySuperId(superId);
			Obj obj=new Obj(true, "获取所有信息分口成功",ports ,  System.currentTimeMillis(), null, "信息分口获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取所有信息分口失败",null ,  System.currentTimeMillis(), "10001", "信息分口获取操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String getInfomationSourceById(Integer id) {
		try {
			InformationSource source =prisonService.getInformationSourceById(id);
			Obj obj=new Obj(true, "获取渠道成功",source ,  System.currentTimeMillis(), null, "信息渠道获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(true, "获取渠道失败",null ,  System.currentTimeMillis(), "10001", "信息渠道获取操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String getInfomationPortById(Integer id) {
		try {
			InformationPort port =prisonService.getInformationPortById(id);
			Obj obj=new Obj(true, "获取渠道成功",port ,  System.currentTimeMillis(), null, "信息渠道获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(true, "获取渠道失败",null ,  System.currentTimeMillis(), "10001", "信息渠道获取操作");
			return gson.toJson(obj);
		}
	}

	@Override
	public String getDetailModifyRecord(Integer recordId, Integer infoId,Integer newrecordId) {
		try {
			if(recordId==null||infoId==null||recordId<=0||infoId<=0){
				Obj obj=new Obj(false, "获取修改记录的详细信息失败", null,  System.currentTimeMillis(), "10002", "信息修改记录获取操作");
				return gson.toJson(obj);
			}
		
			List<ModifyInformationRecord> mRecords=new ArrayList<>();
			ModifyInformationRecord mRecord =prisonService.getModifyRecordByInfoIdAndRecoredId(recordId, infoId);
			mRecords.add(mRecord);
			if (newrecordId!=0) {
				mRecord =prisonService.getModifyRecordByInfoIdAndRecoredId(newrecordId, infoId);
				mRecords.add(mRecord);
			}
			Obj obj=new Obj(true, "获取修改记录的详细信息成功", mRecords,  System.currentTimeMillis(), null, "信息修改记录获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取修改记录的详细信息失败", null,  System.currentTimeMillis(), "10001", "信息修改记录获取操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String getAllStructureOrChildPrison(HttpSession session, HttpServletRequest request) {
		// TODO Auto-generated method stub
		
		try {
			List<PrisonStructure> pStructures = new ArrayList<PrisonStructure>();
			UserPowerView userPowerView = userService.curLoginUserPowerView(session);
			int structureId = userPowerView.getMaxStructure().getId();
			if (structureId==1) {
				 pStructures = prisonService.getDepartmentAndPrisonArea();
			}else{
				PrisonStructure pStructure = prisonService.getStructure(structureId);
				pStructures.add(pStructure);

			}
			Obj obj=new Obj(true, "获取所有部门或者监区成功", pStructures,  System.currentTimeMillis(), null, "监狱结构获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取所有部门或者监区失败", null,  System.currentTimeMillis(), "10001", "监狱结构获取操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String getQuestionStructure() {
		try {
			List<PrisonStructure> pStructures =prisonService.getAllQuestionStructure();
			if (pStructures==null||pStructures.size()<=0||pStructures.isEmpty()) {
				Obj obj=new Obj(false, "获取所有类型为空的部门失败", null,  System.currentTimeMillis(), "10002", "监狱结构获取操作");
				return gson.toJson(obj);
			}
			Obj obj=new Obj(true, "获取所有类型为空的部门成功", pStructures,  System.currentTimeMillis(), null, "监狱结构获取操作");
			return gson.toJson(obj);
		} catch (Exception e) {
			Obj obj=new Obj(false, "获取所有类型为空的部门失败", null,  System.currentTimeMillis(), "10001", "监狱结构获取操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public String modifyQuestionStructure(PrisonStructure pStructure) {
		try {
			if (prisonService.modifyQuestionStructure(pStructure)) {
				Obj obj=new Obj(true, "修改所有类型为空的部门成功", null,  System.currentTimeMillis(), null, "监狱结构获取操作");
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(true, "修改所有类型为空的部门失败", null,  System.currentTimeMillis(), "1002", "监狱结构获取操作");
				return gson.toJson(obj);
			}
				
			
		} catch (Exception e) {
			Obj obj=new Obj(false, "修改所有类型为空的部门失败", null,  System.currentTimeMillis(), "10001", "监狱结构获取操作");
			return gson.toJson(obj);
		}
	}
	@Override
	public void modifyPageReturnType(HttpSession session, HttpServletRequest request) {
		PageReturn pageReturn=(PageReturn) session.getAttribute("pageReturn");
		if (pageReturn!=null) {
			pageReturn.setOpen(true);
		}
		
	}
	@Override
	public String getAllModifyRecord(Integer infoId) {
		List<ModifyInformationRecord> mRecords=modifyInformationRecordDao.getAllModifyRecordByInfoId(infoId);
//		if (mRecords.size()==0||mRecords==null) {
//			
//		}
		Obj obj=new Obj(true, "获取修改记录的详细信息成功", mRecords,  System.currentTimeMillis(), null, "信息修改记录获取操作");
		return gson.toJson(obj);
		
	}
	
	
}
